<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <style type="text/css">
            body{ background-color:#000; color:#eee; font-family:Verdana, Geneva, Sans-Serif }
            select { padding:5px; border-radius: 4px; border: none!important; }
            input { padding:6px; border-radius: 4px; border: none!important; }
            div.logo{ background-image:url('images/logo_big.jpg'); background-repeat:no-repeat; background-position:center center; height:62%; }
            div.main{ height:38%; width:1000px; margin-left:auto; margin-right:auto; }
            div.left{ position:absolute; width:618px; }
            table.list{ font-size:12px; right:0px; }
            td.col_bcon{ width:64px; }
            td.col_dcn{ width:112px; }
            td.col_bmlon{ width:64px; }
            td.col_chassis{ width:144px; }
            td.col_customer{ width:192px; }
            div.right{ position:relative; left:618px; width:382px; }
        </style>
    </head>
    <body>
        <div class="logo"></div>
        <div class="main">
            <div class="left">
                <div class="search">
                    <form name="search" action="index.php" method="get">
                        <select name="k">
                            <option value="bcon">BC ON</option>
                            <option value="dcn">Dealer Contract No.</option>
                            <option value="bmlon">BML ON</option>
                            <option value="chassis">Chassis No.</option>
                            <option value="customer">Customer</option>
                        </select>
                        <input type="text" name="v" size="46" placeholder="Search for order to edit..."/>
                        <input type="submit" value="Find" />
                    </form>
                </div>
                <table class="list"><tbody>
<?php

    // Connect to database
    $link = mysql_connect('localhost', 'root', 'wizapire');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    $db_selected = mysql_select_db('bentley', $link);
    if (!$db_selected) {
        die ('Can\'t use bentley : ' . mysql_error());
    }

    $query_base = 'SELECT bcon, dcn, bmlon, chassis, customer FROM orders';
    
    // Searching by bcon, dcn, or bmlon
    if ($_GET['k'] && $_GET['v'] && in_array($_GET['k'], array('bcon', 'dcn', 'bmlon'))) {
        $query = $query_base . ' WHERE ' . $_GET['k'] . '=' . $_GET['v'];
    }
    
    // Searching by chassis or customer
    else if ($_GET['k'] && $_GET['v'] && in_array($_GET['k'], array('chassis', 'customer'))) {
        $query = $query_base . ' WHERE ' . $_GET['k'] . ' LIKE %' . $_GET['v'] . '%';
    }
    
    // Default when no query is specified
    else {
        $query = $query_base . ' ORDER BY lastupdate DESC LIMIT 8';
    }
    
    
    
    // Query the orders
    $result = mysql_query($query);
    if (!$result) {
        $message  = 'Invalid query: ' . mysql_error() . "\n";
        $message .= 'Whole query: ' . $query;
        echo 'Nothing found.';
        die($message);
    }

    // Display the list
    else{
        echo '<tr class="header">';
        echo '<td class="col_bcon">BC ON</a></td>';
        echo '<td class="col_dcn">Dealer Contract No.</td>';
        echo '<td class="col_bmlon">BML ON</td>';
        echo '<td class="col_chassis">Chassis No.</td>';
        echo '<td class="col_customer">Customer</td>';
        echo '</tr>';
        while ($row = mysql_fetch_assoc($result)) {
            echo '<tr class="list">';
            echo '<td class="col_bcon"><a class="bcon" href="edit.php?bcon=' . $row['bcon'] . '">' . $row['bcon'] . '</a></td>';
            echo '<td class="col_dcn">' . $row['dcn'] . '</td>';
            echo '<td class="col_bmlon">' . $row['bmlon'] . '</td>';
            echo '<td class="col_chassis">' . $row['chassis'] . '</td>';
            echo '<td class="col_customer">' . $row['customer'] . '</td>';
            echo '</tr>';
        }
    }

    mysql_free_result($result);
    mysql_close($link);

?>
                </tbody></table>
            </div>
            <div class="right">
                <div class="import">
                    <form name="search" action="import.php" method="get">
                        <input type="text" name="import" size="32" />
                        <input type="submit" value="Upload" />
                    </form>
                </div>
                <div class="data_export">
                    <p>export</p>
                </div>
            </div>
        </div>
    </body>
</html>
